/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mx.edu.itschapala.sistemas.septimo.Vista;
import com.sun.glass.events.KeyEvent;
import java.awt.Color;
import mx.edu.itschapala.sistemas.septimo.*;
import mx.edu.itschapala.sistemas.septimo.Control.*;
import mx.edu.itschapala.sistemas.septimo.Modelo.*;
import mx.edu.itschapala.sistemas.septimo.Modelo.*;
import mx.edu.itschapala.sistemas.septimo.Vista.enumeracion.*;

/**
 *
 * @author Sony
 */
public class ClienteCrearEditar extends javax.swing.JFrame {

    /**
     * Creates new form ClienteCrearEditar
     */
   
        
    private ClienteLnLocal infoCliente;
    private TipoVentana tipoVentana;
    private Cliente cliente;
    
    public ClienteCrearEditar(Cliente cliente, ClienteLnLocal infoCliente, TipoVentana tipoVentana) {
        this.infoCliente = infoCliente;
        this.tipoVentana = tipoVentana;
        this.cliente=cliente;  
        
        
        initComponents();
        switch (tipoVentana) {
            case VENTANA_REGISTRO:
                jLabel6.setText("REGISTRAR CLIENTE");
                break;
            case VENTANA_EDITAR:
                
                jLabel6.setText("EDITAR NUEVO Cliente");
                
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                //jTextField3.setEditable(false);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                break;
                
            case VENTANA_BUSQUEDA:
                
                jLabel6.setText("BUSCAR POR ID");
                
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                //Cancelar.setVisible(false);
                break;
               
                case VENTANA_ELIMINAR: 
                jLabel6.setText("ELIMINAR UN CLIENTE POR ID");
                jTextField1.remove(cliente.getId());
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                //jTextField3.setEditable(false);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                //Cancelar.setVisible(false);
                break; 
                ////////////////////////////checar
              case VENTANA_LISTAR: 
                jLabel6.setText("LISTAR CLIENTES");
                
                //jTextField2.setEditable(false);
                //jTextField3.setEditable(false);
                //jTextField4.setEditable(false);
                //jTextField5.setEditable(false);
                //Cancelar.setVisible(false);
                
                break;    
                  
                
        }

    
        
    }
        
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        Guardar = new javax.swing.JButton();
        Regresar = new javax.swing.JButton();
        Cancelar = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setForeground(new java.awt.Color(102, 153, 255));
        jPanel1.setLayout(new java.awt.GridLayout(6, 2));

        jPanel2.setLayout(new java.awt.GridLayout(1, 2));

        jLabel1.setText("Nombre ");
        jPanel2.add(jLabel1);
        jPanel2.add(jTextField1);

        jPanel1.add(jPanel2);

        jPanel3.setLayout(new java.awt.GridLayout(1, 2));

        jLabel2.setText("Sexo");
        jPanel3.add(jLabel2);
        jPanel3.add(jTextField2);

        jPanel1.add(jPanel3);

        jPanel4.setLayout(new java.awt.GridLayout(1, 2));

        jLabel3.setText("Id");
        jPanel4.add(jLabel3);

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField3KeyPressed(evt);
            }
        });
        jPanel4.add(jTextField3);

        jPanel1.add(jPanel4);

        jPanel5.setLayout(new java.awt.GridLayout(1, 2));

        jLabel4.setText("Telefono");
        jPanel5.add(jLabel4);
        jPanel5.add(jTextField4);

        jPanel1.add(jPanel5);

        jPanel6.setLayout(new java.awt.GridLayout(1, 2));

        jLabel5.setText("Direccion");
        jPanel6.add(jLabel5);
        jPanel6.add(jTextField5);

        jPanel1.add(jPanel6);

        jPanel7.setLayout(new java.awt.GridLayout(1, 3));

        Guardar.setBackground(new java.awt.Color(51, 102, 255));
        Guardar.setForeground(new java.awt.Color(255, 255, 255));
        Guardar.setText("Guardar");
        Guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GuardarActionPerformed(evt);
            }
        });
        jPanel7.add(Guardar);

        Regresar.setBackground(new java.awt.Color(51, 102, 255));
        Regresar.setForeground(new java.awt.Color(255, 255, 255));
        Regresar.setText("Regresar Al Menu");
        Regresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegresarActionPerformed(evt);
            }
        });
        jPanel7.add(Regresar);

        Cancelar.setText("Cancelar");
        Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarActionPerformed(evt);
            }
        });
        jPanel7.add(Cancelar);

        jPanel1.add(jPanel7);

        jPanel9.setBackground(new java.awt.Color(204, 204, 255));
        jPanel9.setForeground(new java.awt.Color(102, 153, 255));

        jLabel7.setIcon(new javax.swing.ImageIcon("C:\\Users\\Sony\\Pictures\\Fotos proyecto\\Registrar.jpg")); // NOI18N
        jLabel7.setText("jLabel7");

        jLabel6.setText("                                  REGISTRAR CLIENTE");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addGap(0, 33, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GuardarActionPerformed
       switch (tipoVentana) { 
                case VENTANA_REGISTRO:
                    
                Cliente c = new Cliente();
                
                c = new Cliente();
                c.setNombre(jTextField1.getText());
                c.setSexo(jTextField2.getText());
                c.setId(Integer.parseInt(jTextField3.getText()));
                c.setTelefono(Integer.parseInt(jTextField4.getText()));
                c.setDireccion(jTextField5.getText());
                infoCliente.Clienteregistrar(c);
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                break;
            case VENTANA_BUSQUEDA:
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                break;
            case VENTANA_EDITAR:
                c = new Cliente();
                c.setNombre(jTextField1.getText());
                c.setSexo(jTextField2.getText());
                c.setId(Integer.parseInt(jTextField3.getText()));
                c.setTelefono(Integer.parseInt(jTextField4.getText()));
                c.setDireccion(jTextField5.getText());
                infoCliente.Clientemodificar(c);
                
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                jTextField3.setEditable(true);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                
                break;
                case VENTANA_ELIMINAR:
                c = new Cliente();
                c.setNombre(jTextField1.getText());
                c.setSexo(jTextField2.getText());
                c.setId(Integer.parseInt(jTextField3.getText()));
                c.setTelefono(Integer.parseInt(jTextField4.getText()));
                c.setDireccion(jTextField5.getText());
                infoCliente.Clienteeliminar(c);
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                //jTextField3.setEditable(false);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                break;
                          
                } 
    }//GEN-LAST:event_GuardarActionPerformed

    private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarActionPerformed
   this.dispose();
    }//GEN-LAST:event_CancelarActionPerformed

    private void RegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegresarActionPerformed
        this.dispose();
    }//GEN-LAST:event_RegresarActionPerformed

    private void jTextField3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyPressed
        if(tipoVentana!=TipoVentana.VENTANA_REGISTRO){
            if(evt.getKeyCode()==java.awt.event.KeyEvent.VK_ENTER){
                
                Cliente c=infoCliente.ClientebuscarId(Integer.parseInt(jTextField3.getText()));
                if(c!=null){
                    jTextField1.setText(c.getNombre());
                    jTextField2.setText(c.getSexo());
                    jTextField3.setText(c.getId()+"");
                    jTextField4.setText(c.getTelefono()+"");
                    jTextField5.setText(c.getDireccion());
                    
                    if(tipoVentana==TipoVentana.VENTANA_EDITAR){
                        jTextField1.setEditable(true);
                        jTextField2.setEditable(true);
                        jTextField5.setEditable(true);
                        jTextField4.setEditable(true);
                        jTextField3.setEditable(false);
                    }
                }
            }
        }
    }//GEN-LAST:event_jTextField3KeyPressed

    /**
     * @param args the command line arguments
     */
   
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Cancelar;
    private javax.swing.JButton Guardar;
    private javax.swing.JButton Regresar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
